import request from "@/utils/request";
import { getToken, getUserId, getSiteId } from "@/utils/auth";

// 订单属性查询
export function attrQueryApi(params = { keyStr: "", pageNum: 1, pageSize: 10, seriesId: 0 }) {
  return request({
    url: "/OrderAttr1QueryV3/GetOrderAttrList",
    method: "get",
    params: {
      KeyStr: params.keyStr || '',
      AccessToken: getToken(),
      SiteId: getSiteId(),
      SeriesId: params.seriesId,
      PageIndex: params.pageNum || 1,
      PageSize: params.pageSize || 10
    },
  });
}


// 订单属性增改，AttrId=0新增，否则修改
export function attrUpdateApi(
  data = {
    AttrId: 0,
    SeriesId: 0,
    AttrName: 0,
    InputType: "",
    InputType2: "",
    AttrValue: "",
    FixType: 0,
    DefaultValue: "",
    SortIndex: "",
    IsVisible: "",
    ColumnWidth: "",
  }) {
  return request({
    url: "/OrderAttr1AddV3/Post",
    method: "post",
    data: {
      AttrId: data.AttrId,
      SeriesId: data.SeriesId,
      AttrName: data.AttrName,
      InputType: data.InputType,
      InputType2: data.InputType2,
      ColumnWidth: data.ColumnWidth,
      AttrValue: data.AttrValue,
      DefaultValue: data.DefaultValue,
      FixType: data.FixType,
      SortIndex: data.SortIndex,
      IsVisible: data.IsVisible,
      AccessToken: getToken(),
      SiteId: getSiteId(),
    },
  });
}

// 订单属性删除
export function attrRemoveApi(AttrIds = []) {
  return request({
    url: "/OrderAttr1DeleteV3/Post",
    method: "post",
    data: {
      AttrIds: AttrIds.join(','),
      AccessToken: getToken(),
      SiteId: getSiteId(),
    },
  });
}

// 计算属性查询
export function computeQueryApi(params = { keyStr: "", pageNum: 1, pageSize: 10, seriesId: 0 }) {
  return request({
    url: "/OrderAttr2QueryV3/GetOrderAttrList",
    method: "get",
    params: {
      SeriesId: params.seriesId,
      KeyStr: params.keyStr || "",
      AccessToken: getToken(),
      SiteId: getSiteId(),
      PageIndex: params.pageNum || 1,
      PageSize: params.pageSize || 10
    },
  });
}


// 计算属性增改，AttrId=0新增，否则修改
export function computeUpdateApi(
  data = {
    AttrId: 0,
    AttrName: 0,
    InputType: "",
    AttrValue: "",
    AttrRemark: "",
    SortIndex: "",
    seriesId: 0
  }) {
  return request({
    url: "/OrderAttr2AddV3/Post",
    method: "post",
    data: {
      SeriesId: data.seriesId,
      AttrId: data.AttrId,
      AttrName: data.AttrName,
      InputType: data.InputType,
      AttrValue: data.AttrValue,
      AttrRemark: data.AttrRemark,
      SortIndex: data.SortIndex,
      AccessToken: getToken(),
      SiteId: getSiteId(),
    },
  });
}

// 计算属性删除
export function computeRemoveApi(AttrIds = []) {
  return request({
    url: "/OrderAttr2DeleteV3/Post",
    method: "post",
    data: {
      AttrIds: AttrIds.join(','),
      AccessToken: getToken(),
      SiteId: getSiteId(),
    },
  });
}

// 报价方式查询
export function offerQueryApi(params = { keyStr: "", pageNum: 1, pageSize: 10, seriesId: 0 }) {
  return request({
    url: "/OrderAttr3QueryV3/GetOrderAttrList",
    method: "get",
    params: {
      SeriesId: params.seriesId,
      KeyStr: params.keyStr || "",
      AccessToken: getToken(),
      SiteId: getSiteId(),
      PageIndex: params.pageNum || 1,
      PageSize: params.pageSize || 10
    },
  });
}


// 报价方式增改，AttrId=0新增，否则修改
export function offerUpdateApi(
  data = {
    AttrId: 0,
    AttrName: 0,
    AttrValue: "",
    AttrRemark: "",
    IsDefault: "",
    SortIndex: "",
    seriesId: 0
  }) {
  return request({
    url: "/OrderAttr3AddV3/Post",
    method: "post",
    data: {
      SeriesId: data.seriesId,
      AttrId: data.AttrId,
      AttrName: data.AttrName,
      AttrValue: data.AttrValue,
      AttrRemark: data.AttrRemark,
      IsDefault: data.IsDefault,
      SortIndex: data.SortIndex,
      AccessToken: getToken(),
      SiteId: getSiteId(),
    },
  });
}

// 报价方式删除
export function offerRemoveApi(AttrIds = []) {
  return request({
    url: "/OrderAttr3DeleteV3/Post",
    method: "post",
    data: {
      AttrIds: AttrIds.join(','),
      AccessToken: getToken(),
      SiteId: getSiteId(),
    },
  });
}